package com.prd.controller;


import com.prd.dto.CustomerProjectDTO;
import com.prd.service.CustomerProjectService;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 客户-项目 前端控制器
 * </p>
 *
 * @author o1
 * @since 2023-11-24
 */
@Api(tags={"客户管理-项目"})
@RestController
@RequestMapping("/api/customerProject")
public class CustomerProjectController {

    private CustomerProjectService projectService;

    public CustomerProjectController(CustomerProjectService projectService) {
        this.projectService = projectService;
    }

    @ApiOperation("客户模块-UNI-新增简易项目")
    @PostMapping(value = "uAddSimple", produces = "application/json;charset=UTF-8")
    public JsonData uAddSimple(@ApiParam("客户-简易项目") @RequestBody CustomerProjectDTO projectDTO) {
        return projectService.uAddSimple(projectDTO);
    }


    @ApiOperation("客户模块-UNI-项目查询")
    @GetMapping(value = "uSearch")
    public JsonData uSearch(@ApiParam(value = "客户编号") @RequestParam(value = "customer_no", defaultValue = "") String customerNo) {
        return projectService.uSearch(customerNo);
    }

    @ApiOperation("客户模块-UNI-新增/编辑项目")
    @PostMapping(value = "uAddAndUpdate", produces = "application/json;charset=UTF-8")
    public JsonData uAddAndUpdate(@ApiParam("新增/编辑项目CustomerProjectDTO") @RequestBody CustomerProjectDTO projectDTO) {
        return projectService.uAddAndUpdate(projectDTO);
    }


    @ApiOperation("客户模块-客户-UNI-查看各种进度项目条目")
    @GetMapping("uCountCustomerType")
    public JsonData uCountCustomerType() {
        Map<String, Object> map = projectService.uCountProjectBusStatus();
        return JsonData.buildSuccess(map);
    }

    @ApiOperation("客户模块-客户-UNI-修改项目状态，成交2，失败3，取消4，取消则直接删除该项目")
    @PostMapping(value = "uChangeProjectBusStatus", produces = "application/json;charset=UTF-8")
    public JsonData uChangeProjectBusStatus(
            @ApiParam("项目") @RequestBody CustomerProjectDTO projectDTO
    ) {
        return projectService.uChangeProjectBusStatus(projectDTO);
    }


    @ApiOperation("客户模块-客户-UNI-项目分页+筛选")
    @GetMapping("uSearch2")
    public JsonData uSearch2(
            @ApiParam(value = "当前页数") @RequestParam(value = "page", defaultValue = "1") int page,
            @ApiParam(value = "当页数目") @RequestParam(value = "size", defaultValue = "10") int size,
            @ApiParam(value = "项目进度,全部0，洽谈1，成交2，失败3") @RequestParam(value = "projectBusStatus", defaultValue = "-1") int projectBusStatus,
            @ApiParam(value = "关键字") @RequestParam(value = "keyWord", defaultValue = "") String keyWord
    ) {
        Map<String, Object> pageResult = projectService.uSearch2(
                page, size, projectBusStatus, keyWord
        );
        return JsonData.buildSuccess(pageResult);
    }

    @ApiOperation("客户模块-UNI-列表详情")
    @GetMapping(value = "uInfo2")
    public JsonData uInfo2(@ApiParam(value = "项目编号id") @RequestParam(value = "project_id", defaultValue = "") String project_id) {
        return projectService.uInfo2(project_id);
    }
}

